﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using IterationLife.Extensions.Dtos;
using IterationLife.Extensions.Enums;
using Util.Helpers;

namespace IterationLife.Extensions.EasyUI.Commons
{
    /// <summary>
    /// 附件控件
    /// </summary>
    public class AttachmentControl<T> : IAttachmentControl<T>
    {
        /// <summary>
        /// 初始化附件控件
        /// </summary>
        /// <param name="helper">HtmlHelper</param>
        public AttachmentControl(HtmlHelper<T> helper)
        {
            _helper = helper;
        }

        /// <summary>
        /// HtmlHelper
        /// </summary>
        private readonly HtmlHelper<T> _helper;

        /// <summary>
        /// 单附件
        /// </summary>
        public MvcHtmlString SingleEdit<TProperty>(Expression<Func<T, TProperty>> expression, Resources resources, FileType type = FileType.Picture)
        {
            return _helper.Action(
               "SingleEditView",
               "Attachment",
               new
               {
                   area = "Systems",
                   id = resources.Id,
                   address = resources.Address,
                   type = type,
                   labelName = Lambda.GetName(expression)
               });
        }

        /// <summary>
        /// 单附件
        /// </summary>
        public MvcHtmlString SingleEdit(string labelName, Resources resources, FileType type = FileType.Picture)
        {
            return _helper.Action(
                "SingleEditView",
                "Attachment",
                new
                {
                    area = "Systems",
                    id = resources.Id,
                    address = resources.Address,
                    type = type,
                    labelName = labelName
                });
        }

        /// <summary>
        /// 单附件预览
        /// </summary>
        public MvcHtmlString SinglePreview(Resources resources)
        {
            return _helper.Action(
               "SinglePreviewView",
               "Attachment",
               new
               {
                   area = "Systems",
                   id = resources.Id,
                   address = resources.Address
               });
        }
    }
}
